package com.oms.base;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;

/**
 * JSON年月日时分秒格式序列化
 * @author Loong_Mit
 * @date Sep 27, 2012 10:52:55 PM
 */

public class JSONDateTimeSerializer extends JsonSerializer<Date>{
	
	private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	@Override
	public void serialize(Date date, JsonGenerator generator, SerializerProvider serializer)
			throws IOException, JsonProcessingException {
		if (date != null) {
			generator.writeString(dateFormat.format(date));
		}
	} 
}